<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Districts
 *
 * @author Administrator
 */
class Districts {

    private $ID;
    private $Name;
    private $Type;
    private $Location;
    private $ProvinceID;
    private $Province;

    public function getID() {
        return $this->ID;
    }

    public function setID($ID) {
        $this->ID = $ID;
    }

    public function getName() {
        return $this->Name;
    }

    public function setName($Name) {
        $this->Name = $Name;
    }

    public function getType() {
        return $this->Type;
    }

    public function setType($Type) {
        $this->Type = $Type;
    }

    public function getLocation() {
        return $this->Location;
    }

    public function setLocation($Location) {
        $this->Location = $Location;
    }

    public function getProvinceID() {
        return $this->ProvinceID;
    }

    public function setProvinceID($ProvinceID) {
        $this->ProvinceID = $ProvinceID;
    }

    public function getProvince() {
        return $this->Province;
    }

    public function setProvince($Province) {
        $this->Province = $Province;
    }

    
    public function getByID($db = null) {
        if ($db != null) {
            $sql = "SELECT
                    `D_ID`,
                    `D_Name`,
                    `D_Type`,
                    `D_Location`,
                    `D_P_ID`
                  FROM `districts`
                  WHERE D_ID = :D_ID";

            $parameters = array(':D_ID');
            $values = array($this->getID());
            $types = array(PDO::PARAM_INT);
            $result = $db->executeQuery($sql, $parameters, $values, $types);

            // nếu có kết quả
            if ($result != null) {
                $row = $result->fetch();
                $this->setID($row->D_ID);
                $this->setName($row->D_Name);
                $this->setType($row->D_Type);
                $this->setLocation($row->D_Location);
                $this->setProvinceID($row->D_P_ID);
                
                return $this;
            } else {
                return null;
            }
        }
    }

}

?>
